package com.maozzi.web.configuration;

import com.maozzi.api.acl.AclService;
import com.maozzi.api.user.UserService;
import com.maozzi.web.auth.AuthInterceptor;
import com.maozzi.web.auth.LoginInterceptor;

import javax.annotation.Resource;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * MVC配置
 *
 * @author maozi
 */
@Configuration
public class MvcConfig implements WebMvcConfigurer {

    @Resource
    private LoginInterceptor loginInterceptor;

    @Resource
    private AuthInterceptor authInterceptor;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        // 登录拦截
        registry.addInterceptor(loginInterceptor)
                .addPathPatterns("/**")
                .excludePathPatterns("/view/**", "/favicon.ico", "/")
        ;
        // 权限拦截，适用于admin 权限校验
        registry.addInterceptor(authInterceptor)
                .addPathPatterns("/rest/back/**")
                .excludePathPatterns("/favicon.ico")
        ;
    }

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        // 解决favicon.ico 404问题
        registry.addResourceHandler("/favicon.ico")
                .addResourceLocations("classpath:/static/");
    }
}
